<template>
  <div class="workbench">
    <div class="tabs-box">
      <div class="tabs-content">
        <div class="list" v-for="(item, index) in listData" :key="index">
          <div
            v-lazy:background-image="
              $options.filters.filterUserLazyImg(item.admin_realname)
            "
            :key="index"
            class="div-photo"
          ></div>
          <div class="img-text">
            <div class="name-time">
              <p class="name-behavior">
                <span class="name" v-if="item.admin_realname">{{
                  item.admin_realname
                }}</span>
              </p>
              <p class="time">{{ item.send_time | moment("YYYY-MM-DD HH:mm") }}</p>
            </div>
            <div class="log-title">
              <img class="img-5" src="@/assets/img/work_examine.png" />
              <span class="type-name">{{ item.type }}</span>
            </div>
            <div class="title" v-if="item.content">
              <span @click="rowFun(item)" ref="taskRow">{{ item.content }}</span>
            </div>
          </div>
        </div>
        <p class="load">
          <el-button type="text" :loading="loadMoreLoading">{{ loadText }}</el-button>
        </p>
        <!-- 审批详情 -->
        <inform-detail
          v-if="informShow"
          :id="noticeId"
          :noListenerClass="['tabs-content']"
          @hide-view="informShow = false"
        />
      </div>
    </div>
  </div>
</template>

<script>
// API
import { oaNoticeList } from "@/api/oamanagement/workbench";
import InformDetail from "./InformDetail.vue";

export default {
  components: {
    InformDetail,
  },
  data() {
    return {
      // 列表数据
      listData: [],
      loading: true,
      // 页数
      loadMoreLoading: true,
      pageNum: 1,
      loadText: "加载更多",
      isPost: false,
      // 是否显示审批
      noticeId: null,
      informShow: false,
    };
  },
  mounted() {
    this.workbenchData(this.pageNum);
    // 分批次加载
    let _this = this;
    for (let item of document.getElementsByClassName("el-tabs__content")) {
      item.onscroll = function () {
        let doms = item;
        var scrollTop = doms.scrollTop;
        var windowHeight = doms.clientHeight;
        var scrollHeight = doms.scrollHeight;
        //滚动条到底部的条件
        if (scrollTop + windowHeight == scrollHeight && _this.loadMoreLoading == true) {
          if (!_this.isPost) {
            _this.isPost = true;
            _this.pageNum++;
            _this.workbenchData(_this.pageNum);
          } else {
            _this.loadMoreLoading = false;
          }
        }
      };
    }
  },
  methods: {
    // 获取数据
    workbenchData(page) {
      oaNoticeList({
        page: page,
        limit: 15,
      })
        .then((res) => {
          this.listData = this.listData.concat(res.data.list);
          if (Math.ceil(res.data.dataCount / 15) <= page) {
            this.loadText = "没有更多了";
            this.loadMoreLoading = false;
          } else {
            this.loadText = "加载更多";
            this.loadMoreLoading = true;
          }
          this.loading = false;
          this.isPost = false;
        })
        .catch((err) => {
          this.loadText = "";
          this.loading = false;
          this.isPost = false;
        });
    },
    rowFun(val) {
      this.noticeId = val.notice_id;
      this.informShow = true;
    },
  },
};
</script>

<style scoped lang="scss">
@import "../styles/tabs.scss";

$colorF: #fff;
.workbench {
  height: 100%;
  min-height: 720px;
  width: 100%;
  .tabs-box {
    background: $colorF;
    height: 100%;
    border: 1px solid rgba(230, 230, 230, 1);
    border-radius: 4px;
    .load {
      color: #999;
      font-size: 13px;
      margin: 0 auto 15px;
      text-align: center;
      .el-button,
      .el-button:focus {
        color: #ccc;
        cursor: auto;
      }
    }
  }
}

.tabs-content {
  margin: 0 30px;
  padding: 20px 0;

  .list {
    font-size: 13px;
    padding: 20px 0;
    border-bottom: 1px solid #f1f1f1;

    .div-photo {
      width: 35px;
      height: 35px;
      border-radius: 17.5px;
      float: left;
    }

    .img-text {
      margin-left: 50px;

      .name-time {
        display: inline-block;

        .name-behavior {
          margin-bottom: 6px;

          .name {
            margin-right: 10px;
            color: #333;
            font-size: 15px;
          }
        }

        .time {
          color: #999;
          font-size: 12px;
        }
      }

      .log-title {
        float: right;
        margin-top: 6px;

        img,
        .type-name {
          vertical-align: middle;
          width: 20px;
        }

        .img-5 {
          margin-bottom: 3px;
        }
      }

      .title {
        margin: 20px 0 0;
        color: #3e84e9;
        white-space: pre-wrap;
        word-wrap: break-word;
        letter-spacing: 0.5px;
        line-height: 18px;
        background-color: #f4f7fd;
        padding: 10px;
        border-radius: 2px;

        span {
          cursor: pointer;
        }
      }

      .title :hover {
        text-decoration: underline;
      }
    }
  }

  .list:last-child .title {
    border: 0;
  }

  .list:first-child {
    padding-top: 5px;
  }
}
</style>
